//
//  HLFoldCourseCell.m
//  HLAerospace
//
//  Created by hulian-ios on 17/9/8.
//  Copyright © 2017年 hulian-LB. All rights reserved.
//

#import "HLFoldCourseCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <Masonry/Masonry.h>
#import "HLFoldCourse.h"
#import "HLSubDetail.h"

#define kTableViewRowHeight IS_IPHONE_5 ? 44 : 50

@interface HLFoldCourseCell ()

/** iconView  */
@property (nonatomic ,strong) UIImageView *iconView;
/** head  */
@property (nonatomic ,strong) UILabel *headTitle;
/** title  */
@property (nonatomic ,strong) UILabel *title;
/** line  */
@property (nonatomic ,strong) UIView *line;

@end

@implementation HLFoldCourseCell

- (UIImageView *)iconView
{
    if (!_iconView ) {
        _iconView = [[UIImageView alloc] init];
    }
    return _iconView;
}

- (UILabel *)title
{
    if (!_title ) {
        _title = [[UILabel alloc] init];
        _title.backgroundColor = [UIColor clearColor];
        _title.textColor = HLRGB(60, 60, 60);
        _title.font = [UIFont systemFontOfSize:IS_IPHONE_5 ? 12: kMainTitleFontSize];
    }
    return _title;
}

- (UIView *)line
{
    if (!_line) {
        _line = [[UIView alloc]init];
        _line.backgroundColor = HLRGB(235, 235, 235);
    }
    return _line;
}

- (UILabel *)headTitle
{
    if (!_headTitle) {
        _headTitle = [[UILabel alloc]init];
        _headTitle.backgroundColor = [UIColor clearColor];
        _headTitle.textColor = HLRGB(120, 120, 120);
        _headTitle.font = [UIFont systemFontOfSize:IS_IPHONE_5 ? 11: 12];
    }
    return _headTitle;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsZero;
        self.clipsToBounds = YES;
        self.backgroundColor = HLRGB(245, 245, 245);

        [self setUI];
    }
    return self;
}

- (void)setUI
{
    [self.contentView addSubview:self.title];
    [self.contentView addSubview:self.headTitle];
    [self.contentView addSubview:self.iconView];
    [self.contentView addSubview:self.line];
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.bottom.equalTo(self.contentView).offset(IS_IPHONE_5 ? -14 : -16);
        make.height.equalTo(@(18));
        make.width.equalTo(@(40));
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(10);
        make.right.equalTo(self.mas_right).offset(-10);
        make.centerY.equalTo(self.iconView);
        make.height.equalTo(@(30));
        
    }];
    
    [self.headTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(4);
        make.left.equalTo(self).offset(15);
        make.height.equalTo(@(17));
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.bottom.equalTo(self);
        make.width.equalTo(@(self.width - 20));
        make.height.equalTo(@(1));
    }];
    
}

- (void)setFoldCourse:(HLFoldCourse *)foldCourse
{
    _foldCourse = foldCourse;
    
    if([foldCourse.type isEqualToString:@"1"] ){
        self.title.text = [NSString stringWithFormat:@"微视频:%@",foldCourse.wkname];
        self.iconView.image = [UIImage imageNamed:@"home_course_fold_video"];
    }
    if([foldCourse.type isEqualToString:@"2"] ){
        self.title.text = [NSString stringWithFormat:@"微文档:%@",foldCourse.wkname];
        self.iconView.image = [UIImage imageNamed:@"home_course_fold_pdf"];
    }
    
    self.headTitle.text = foldCourse.headTitleText;
    self.line.hidden = foldCourse.isHeadLine;
}

- (void)setSubDetail:(HLSubDetail *)subDetail
{
    _subDetail = subDetail;
    
    if(subDetail.type == 1 ){
        self.title.text = [NSString stringWithFormat:@"微视频:%@",subDetail.wkname];
        self.iconView.image = [UIImage imageNamed:@"home_course_fold_video"];
    }
    if(subDetail.type == 2){
        self.title.text = [NSString stringWithFormat:@"微文档:%@",subDetail.wkname];
        self.iconView.image = [UIImage imageNamed:@"home_course_fold_pdf"];
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end
